export class ChromeUtil {

    constructor() {

    }

    // content {from: string, to: string, type: string, data: any}
    static sendRuntimeMsg(content, resolve = undefined) {
        if (!content || !chrome || !chrome.runtime) {
            return;
        }
        return chrome.runtime.sendMessage(chrome.runtime.id, { from: 'popup', ...content }, resolve);
    }

    // content {from: string, to: string, type: string, data: any}
    static sendTabsMsg(content) {
        if (!content || !chrome || !chrome.tabs) {
            return;
        }
        chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
            chrome.tabs.sendMessage(tabs[0].id, { from: 'popup', ...content });
        })
    }

    static storageLocalSet(content) {
        if (!content || !chrome || !chrome.storage) {
            return;
        }
        try {
            chrome.storage.local.set(content);
        } catch { }
    }
}
